package routes

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"main/app/controller"
	"main/app/middleware"
	"main/app/model"
	//"fmt"

)

func InitRoute() *gin.Engine{
	r := gin.Default()

	r.Static("/static","web/static")
	r.LoadHTMLGlob("web/template/*")

	//登录注册
	r.POST("login",controller.Login)
	r.POST("register",controller.Register)

	//首页
	r.GET("/",func(c *gin.Context){
		JSONData,err := model.SelectArticle("")
		if err!=nil{
			c.JSON(http.StatusOK,gin.H{
				"articleList":"",
			})
		}else{
			c.HTML(http.StatusOK,"index.html",gin.H{
				"articleList":JSONData,
			})
		}
	})

	r.POST("search",controller.SelectArticle)



	V1Group := r.Group("/v1",middleware.Verify())
	{
		V1Group.POST("/detail",controller.FindArticle)
	}
	return r
}
